<?php
include('class/class_connect.php');
include('class/class_page.php');
include('class/class_address.php');
include('class/class_workdays.php');
include('class/class_rating.php');
include('class/class_news.php');
include('class/abstract/class_mainObjectInfo.php');
include('class/abstract/class_paginator.php');
include('class/city_rus.php');
include('class/class_checkGetData.php');
if($_GET['obj']=='nets')
{
	$aCheck=new checkGetData('main');
	$aCheck->checkCity('nets');
	$aCheck->checkTableId('nets', $_GET['id']);
	$aConnect=new connect('main');
	$row=mysql_fetch_array($aConnect->select_all('nets', "WHERE id='".$_GET['id']."'"));
}
else
{
	$aCheck=new checkGetData(substr($_GET['obj'],0,1));
	$aCheck->checkCity($_GET['city']);
	$aCheck->checkTableId($_GET['city'], $_GET['id']);
	$aConnect=new connect(substr($_GET['obj'],0,1));
	$row=mysql_fetch_array($aConnect->select_all($_GET['city'], "WHERE id='".$_GET['id']."'"));
}
foreach($_GET as $key=>$val)
{
	$_GET[$key]=checkGetData::safetyCheck($val);
}
if(!$_GET['obj']=='firms' || !$_GET['obj']=='malls' || !$_GET['obj']=='nets')
	exit;

session_start();

class aFirmPage extends page
{
	var $row=array();
	var $cityRus;
	function __construct($row)
	{
		$this->row=$row;
		$this->cityRus=new city_rus_class();
		parent::__construct();
	}
	function title()
	{
		echo $this->row['name'].' '.$this->cityRus->city_rus_im($_GET['city']);
	}
	function maincontent()
	{
		if($_GET['obj']=='nets')$objRus='Мои сети';
		elseif($_GET['obj']=='firms')$objRus='Мои фирмы';
		elseif($_GET['obj']=='malls')$objRus='Мои центры';
		echo ('
		<div class="route">
			<div class="routeEl">
				<a href="pcabinet.php?city='.$_GET['city'].'">Личный кабинет</a>
			</div>
			<div class="routeEl">
				<a href="my_'.$_GET['obj'].'.php?city='.$_GET['city'].'">'.$objRus.'</a>
			</div>
			<div class="routeEl">
				<a href="'.$_GET['obj'].'cabinet.php?city='.$_GET['city'].'&id='.$_GET['id'].'">'.$this->row['name'].'</a>
			</div>
			<div class="routeEl">
				Новости
			</div>
		</div>
		');
		$aFirmInfo=new aFirmInfo($this->row);
		echo '<center><h1>Новости</h1></center>';
        $aPaginator=new newsPaginator();
	}
}


class aFirmInfo extends mainObjectInfo
{
	var $row;
	function __construct($row=array())
	{
		$this->row=$row;
		parent::__construct();
	}
	function showPic()
	{
		$img='<img src="pictures/'.$_GET['obj'].'pics/'.$_GET['city'].'/'.$_GET['id'].'.jpg" title="'.$this->name.'">';
		if($_GET['obj']=='nets')$img='<img src="pictures/'.$_GET['obj'].'pics/'.$_GET['id'].'.jpg" title="'.$this->name.'">';
		echo $img;
	}
	function showAddress()
	{
		$address=new address();
		if($_GET['obj']=='firms')
			$address->showSeveralAddresses($this->row['address'], $this->row['link']);
		else
		{
			$addr=explode(',', $this->row['address']);
			$explAddress=$addr[0].'^'.$addr[1].'^'.$this->row['phone'].'^^'.$this->row['workdays'];
			$address->showAddress($explAddress,  $this->row['link']);
		}
	}
	function showshort()
	{
		echo $this->row['short'];
	}
	function showName()
	{
		echo $this->row['name'];
	}
}
class newsPaginator extends paginator
{
	var $res=array();
	var $newsNum;
	function __construct()
	{		if($_GET['obj']=='nets')
		{			$aConnect=new connect('main');
			$this->res=$aConnect->select_all('nets_news', "WHERE ".$_GET['obj']."_id='".$_GET['id']."'");
		}
		else
		{
			$aConnect=new connect(substr($_GET['obj'],0,1).'n');
			$this->res=$aConnect->select_all($_GET['city'], "WHERE ".$_GET['obj']."_id='".$_GET['id']."'");
		}
		$this->newsNum=mysql_num_rows($this->res);
		//$this->row=mysql_fetch_array($res);
		parent::__construct(15);
	}
	function pageContent()
	{
		$news=new news($_GET['obj'], $_GET['city'], $_GET['id'], true);
		if($_GET['obj']=='nets')
		{
			$aConnect=new connect('main');
			$res=$aConnect->select_all('nets_news', "WHERE ".$_GET['obj']."_id='".$_GET['id']."' ORDER BY data DESC LIMIT ".$this->lim.", ".$this->limit."");
		}
		else
		{
			$aConnect=new connect(substr($_GET['obj'],0,1).'n');
			$res=$aConnect->select_all($_GET['city'], "WHERE ".$_GET['obj']."_id='".$_GET['id']."' ORDER BY data DESC LIMIT ".$this->lim.", ".$this->limit."");
		}
		echo ('
		<div class="news">
		');
		while($row=mysql_fetch_array($res))
		{
			$news->showANews($row['id'], $row['name'], $row['stext'], $row['data'], 'edit'.$_GET['obj'].'news.php?city='.$_GET['city'].'&id=', 1000);
		}
		echo ('
		</div>
		');
	}
	function countRows()
	{
		return($this->newsNum);
	}
}
$aPage=new aFirmPage($row);

?>